package com.op.teachingliteapp.util.http;

import android.graphics.Bitmap;
import android.util.Log;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

public class MemoryCache implements ImageLoader.ImageCache {

	private static final String TAG = MemoryCache.class.getSimpleName();
	private LruCache<String, Bitmap> mCache;

	public MemoryCache() {
		int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
		int cacheSize = maxMemory / 8;
		mCache = new LruCache<String, Bitmap>(cacheSize) {
			@Override
			protected int sizeOf(String key, Bitmap bitmap) {
				return bitmap.getRowBytes() * bitmap.getHeight();
			}
		};
	}

	@Override
	public Bitmap getBitmap(String url) {
//		Log.i(TAG, "get : " + url);
		return mCache.get(url);
	}

	@Override
	public void putBitmap(String url, Bitmap bitmap) {
		mCache.put(url, bitmap);
//		Log.i(TAG, "put : " + url);
	}

}
